home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_008 / src / hack.options.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  158 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* hack.options.c version 1.0.1 - added HACKOPTIONS */
  3.  
  4. #include "config.h"
  5. #ifdef OPTIONS
  6. #include "hack.h"
  7. extern char *eos();
  8.  
  9. initoptions()
  10. {
  11.     register char *opts;
  12.     extern char *getenv();
  13.  
  14.     flags.time = flags.nonews = flags.notombstone = flags.end_own =
  15.     flags.no_rest_on_space = FALSE;
  16.     flags.end_top = 5;
  17.     flags.end_around = 4;
  18.     /* flags.oneline is set in hack.tty.c depending on the baudrate */
  19.  
  20.     if(opts = getenv("HACKOPTIONS"))
  21.         parseoptions(opts,TRUE);
  22. }
  23.  
  24. parseoptions(opts, from_env)
  25. register char *opts;
  26. boolean from_env;
  27. {
  28.     register char *op,*op2;
  29.     unsigned num;
  30.     boolean negated;
  31.  
  32.     if(op = index(opts, ',')) {
  33.         *op++ = 0;
  34.         parseoptions(op, from_env);
  35.     }
  36.     if(op = index(opts, ' ')) {
  37.         op2 = op;
  38.         while(*op++)
  39.             if(*op != ' ') *op2++ = *op;
  40.     }
  41.     if(!*opts) return;
  42.     negated = FALSE;
  43.     while((*opts == '!') || !strncmp(opts, "no", 2)) {
  44.         if(*opts == '!') opts++; else opts += 2;
  45.         negated = !negated;
  46.     }
  47.     if(!strncmp(opts,"tombstone",4)) {
  48.         flags.notombstone = negated;
  49.         return;
  50.     }
  51.     if(!strncmp(opts,"news",4)) {
  52.         flags.nonews = negated;
  53.         return;
  54.     }
  55.     if(!strncmp(opts,"time",4)) {
  56.         flags.time = !negated;
  57.         flags.botl = 1;
  58.         return;
  59.     }
  60.     if(!strncmp(opts,"oneline",1)) {
  61.         flags.oneline = !negated;
  62.         return;
  63.     }
  64.     if(!strncmp(opts,"restonspace",4)) {
  65.         flags.no_rest_on_space = negated;
  66.         return;
  67.     }
  68.     /* endgame:5t[op] 5a[round] o[wn] */
  69.     if(!strncmp(opts,"endgame",3)) {
  70.         op = index(opts,':');
  71.         if(!op) goto bad;
  72.         op++;
  73.         while(*op) {
  74.             num = 1;
  75.             if(digit(*op)) {
  76.                 num = atoi(op);
  77.                 while(digit(*op)) op++;
  78.             } else
  79.             if(*op == '!') {
  80.                 negated = !negated;
  81.                 op++;
  82.             }
  83.             switch(*op) {
  84.             case 't':
  85.                 flags.end_top = num;
  86.                 break;
  87.             case 'a':
  88.                 flags.end_around = num;
  89.                 break;
  90.             case 'o':
  91.                 flags.end_own = !negated;
  92.                 break;
  93.             default:
  94.                 goto bad;
  95.             }
  96.             while(letter(*++op)) ;
  97.             if(*op == '/') op++;
  98.         }
  99.         return;
  100.     }
  101. bad:
  102.     if(!from_env) {
  103.         if(!strncmp(opts, "help", 4)) {
  104.             pline("%s%s%s",
  105. "To set options use `HACKOPTIONS=\"<options>\"' in your environment, or ",
  106. "give the command 'o' followed by the line `<options>' while playing. ",
  107. "Here <options> is a list of <option>s separated by commas." );
  108.             pline("%s%s",
  109. "Simple (boolean) options are oneline,rest_on_space,news,time,tombstone. ",
  110. "These can be negated by prefixing them with '!' or \"no\"." );
  111.             pline("%s%s%s",
  112. "A compound option is endgame; it is followed by a description of what ",
  113. "parts of the scorelist you want to see. You might for example say: ",
  114. "`endgame:own scores/5 top scores/4 around my score'." );
  115.             return;
  116.         }
  117.         pline("Bad option: %s.", opts);
  118.         pline("Type `o help<cr>' for help.");
  119.         return;
  120.     }
  121.     puts("Bad syntax in HACKOPTIONS.");
  122.     puts("Use for example:");
  123.     puts(
  124. "HACKOPTIONS=\"!restonspace,notombstone,endgame:own/5 topscorers/4 around me\""
  125.     );
  126.     getret();
  127. }
  128.  
  129. doset()
  130. {
  131.     char buf[BUFSZ];
  132.  
  133.     pline("What options do you want to set? ");
  134.     getlin(buf);
  135.     if(!buf[0]) {
  136.         (void) strcpy(buf,"HACKOPTIONS=");
  137.         if(flags.oneline) (void) strcat(buf,"oneline,");
  138.         if(flags.nonews) (void) strcat(buf,"nonews,");
  139.         if(flags.time) (void) strcat(buf,"time,");
  140.         if(flags.notombstone) (void) strcat(buf,"notombstone,");
  141.         if(flags.no_rest_on_space)
  142.         (void) strcat(buf,"!rest_on_space,");
  143.         if(flags.end_top != 5 || flags.end_around != 4 || flags.end_own){
  144.         (void) sprintf(eos(buf), "endgame: %d topscores/%d around me",
  145.             flags.end_top, flags.end_around);
  146.         if(flags.end_own) (void) strcat(buf, "/own scores");
  147.         } else {
  148.         register char *eop = eos(buf);
  149.         if(*--eop == ',') *eop = 0;
  150.         }
  151.         pline(buf);
  152.     } else
  153.         parseoptions(buf, FALSE);
  154.  
  155.     return(0);
  156. }
  157. #endif OPTIONS
  158.